﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;

namespace Freshome.b
{
    [DataContract]
    public class Shortype
    {
        [DataMember]
        [Key]
        public short Mid { get; set; }

        [DataMember]
        [NotMapped]
        [StringLength(50)]
        public string Stamp { get; set; }

        [DataMember]
        [StringLength(50)]
        [Required]
        public string Notes { get; set; }
    }
    [DataContract]
    [Table("Majoraw")]
    public class Majoraw : Shortype
    {
        [DataMember]
        [Required]
        [StringLength(10, MinimumLength = 2)]
        public string Name { get; set; }

        public byte Categ { get; set; }

        [DataMember]
        [NotMapped]
        public MajorawCateg Category
        {
            get
            {
                if (Enum.IsDefined(typeof(MajorawCateg), this.Categ)) return (MajorawCateg)this.Categ;
                else return MajorawCateg.None;
            }
            set
            {
                this.Categ = (byte)value;
            }
        }
        [DataMember]
        public ICollection<Majorecipe> Recipes { get; set; }

        [DataMember]
        public ICollection<Pairaw> Pairs { get; set; }

        [DataMember]
        public ICollection<Rawithealth> Healtholds { get; set; }
    }
    [DataContract]
    [Table("Minoraw")]
    public class Minoraw : Shortype
    {
        [DataMember]
        [Required]
        [StringLength(10, MinimumLength = 2)]
        public string Name { get; set; }

        public byte Categ { get; set; }

        [DataMember]
        [NotMapped]
        public MinorawCateg Category
        {
            get
            {
                if (Enum.IsDefined(typeof(MinorawCateg), this.Categ)) return (MinorawCateg)this.Categ;
                else return MinorawCateg.None;
            }
            set
            {
                this.Categ = (byte)value;
            }
        }
        [DataMember]
        public ICollection<Minorecipe> Recipes { get; set; }
    }
    [DataContract]
    [Table("Recipe")]
    public class Recipe : Shortype
    {
        [DataMember]
        [Required]
        [StringLength(10, MinimumLength = 2)]
        public string Name { get; set; }

        public byte Categ { get; set; }

        [DataMember]
        [NotMapped]
        public RecipeCateg Category
        {
            get
            {
                if (Enum.IsDefined(typeof(RecipeCateg), this.Categ)) return (RecipeCateg)this.Categ;
                else return RecipeCateg.None;
            }
            set
            {
                this.Categ = (byte)value;
            }
        }
        public byte Season { get; set; }

        [DataMember]
        [NotMapped]
        public bool Spring
        {
            get { return (this.Season & 0x01) == 0x01; }
            set
            {
                if (value) this.Season |= 0x01;
                else this.Season &= 0xfe;
            }
        }
        [DataMember]
        [NotMapped]
        public bool Summer
        {
            get { return (this.Season & 0x02) == 0x02; }
            set
            {
                if (value) this.Season |= 0x02;
                else this.Season &= 0xfd;
            }
        }
        [DataMember]
        [NotMapped]
        public bool Autumn
        {
            get { return (this.Season & 0x04) == 0x04; }
            set
            {
                if (value) this.Season |= 0x04;
                else this.Season &= 0xfb;
            }
        }
        [DataMember]
        [NotMapped]
        public bool Winter
        {
            get { return (this.Season & 0x08) == 0x08; }
            set
            {
                if (value) this.Season |= 0x08;
                else this.Season &= 0xf7;
            }
        }
        [DataMember]
        [NotMapped]
        public bool MeatRiceFarciHot // Meat:荤素,Rice:米面,Farci:有馅,Hot:冷热
        { 
            get { return (this.Season & 0x80) == 0x80; }
            set
            {
                if (value) this.Season |= 0x80;
                else this.Season &= 0x7f;
            }
        }

        [DataMember]
        public byte[] ImageData { get; set; }

        [DataMember]
        public string ImageType { get; set; }

        [DataMember]
        public ICollection<Minorecipe> Minors { get; set; }

        [DataMember]
        public ICollection<Majorecipe> Majors { get; set; }

        [DataMember]
        public ICollection<Steplan> Steps { get; set; }

        [DataMember]
        public ICollection<Comment> Comments { get; set; }
    }
    [DataContract]
    [Table("Healthold")]
    public class Healthold : Shortype
    {
        [DataMember]
        [Required]
        [StringLength(10, MinimumLength = 2)]
        public string Name { get; set; }

        [DataMember]
        public ICollection<Rawithealth> Rawithes { get; set; }
    }
    [DataContract]
    [Table("Majorecipe")]
    public class Majorecipe : Shortype
    {
        [DataMember]
        public bool Prime { get; set; }

        [DataMember]
        public short Jmx { get; set; }
        [ForeignKey("Jmx")]
        public Majoraw Majoraw { get; set; }

        [DataMember]
        public short Rmx { get; set; }
        [ForeignKey("Rmx")]     // no DataMember attribute, important for WCF
        public Recipe Recipe { get; set; }

        [DataMember]
        [NotMapped]
        public string Parentitle { get; set; }
    }
    [DataContract]
    [Table("Pairaw")]
    public class Pairaw : Shortype
    {
        [DataMember]
        [Required]
        [StringLength(10, MinimumLength = 2)]
        public string Mate { get; set; }

        [DataMember]
        public bool Taboo { get; set; }

        [DataMember]
        public short Jmx { get; set; }
        [ForeignKey("Jmx")]
        public Majoraw Majoraw { get; set; }
    }
    [DataContract]
    [Table("Minorecipe")]
    public class Minorecipe : Shortype
    {
        [DataMember]
        public short Imx { get; set; }
        [ForeignKey("Imx")]
        public Minoraw Minoraw { get; set; }

        [DataMember]
        public short Rmx { get; set; }
        [ForeignKey("Rmx")]     // no DataMember attribute, important for WCF
        public Recipe Recipe { get; set; }

        [DataMember]
        [NotMapped]
        public string Parentitle { get; set; }
    }
    [DataContract]
    [Table("Steplan")]
    public class Steplan : Shortype
    {
        [DataMember]
        public byte Planum { get; set; }

        [DataMember]
        public short Rmx { get; set; }
        [ForeignKey("Rmx")]         // no DataMember attribute, important for WCF
        public Recipe Recipe { get; set; }
    }
    [DataContract]
    [Table("Rawithealth")]
    public class Rawithealth : Shortype
    {
        [DataMember]
        public bool Taboo { get; set; }

        [DataMember]
        public short Jmx { get; set; }
        [ForeignKey("Jmx")]
        public Majoraw Majoraw { get; set; }

        [DataMember]
        public short Hmx { get; set; }
        [ForeignKey("Hmx")]
        public Healthold Healthold { get; set; }

        [NotMapped]
        public string Parentitle { get; set; }
    }
    /// <summary>
    /// Notice: Intype标识列类型为Int，需要特殊处理
    /// </summary>
    [DataContract]
    public class Intype
    {
        [DataMember]
        [Key]
        public int Tid { get; set; }

        [DataMember]
        [NotMapped]
        [StringLength(50)]
        public string Stamp { get; set; }

        [DataMember]
        [StringLength(50)]
        public string Notes { get; set; }
    }
    [DataContract]
    [Table("Comment")]
    public class Comment : Intype
    {
        [DataMember]
        public DateTime Datime { get; set; }

        [DataMember]
        public short Rmx { get; set; }
        [ForeignKey("Rmx")]         // no DataMember attribute, important for WCF
        public Recipe Recipe { get; set; }
    }
}
